<extend name="./public/frame.html"/>
<block name="content">
    <style>
        .layui-form-label{width: 10%;}
        .layui-input-block{margin-left: 12%;}
    </style>
    <form class="layui-form layui-form-pane1" action="" method="post" enctype="multipart/form-data">
        <div class="layui-form-item">
            <label class="layui-form-label">品牌名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" placeholder="品牌名称"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">品牌首字母</label>
            <div class="layui-input-block">
                <input type="text" name="initials" lay-verify="required" placeholder="品牌首字母"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">品牌LOGO</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn uploads"  id="upload-CarBrand}" >上传图片</button>
                <br/>
                <img  id="pic_url" layer-src="" src="" width="100px;" height="100px;" style="display: none;">
                <input name="pic_url" id="pic_urlk" type="hidden" value="">
                <input name="file_thumb" id="file_thumb" type="hidden" value="">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="显示" checked>
                <input type="radio" name="status" value="0" title="隐藏">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="sort" lay-verify="required" placeholder="排序"
                       autocomplete="off" class="layui-input" value="100">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script>
        layui.use(['upload','form'], function () {
                upload = layui.upload
                ,form = layui.form;
            upload.render({
                elem: '.uploads'//这个就等同于点击
                ,url: '/admin/Upload/uploadCarBrand'
                ,done:  function(res){ //上传后的回调
                    console.log(res)
                    if(res.status == 1){
                        $("#pic_url").css('display','');
                        $("#pic_url").attr('src',res.data.file); //点击后的大图
                        $("#pic_url").attr('layer-src',res.data.file_thumb); //小图
                        $("#pic_urlk").val(res.data.file); //点击后的大图
                        $("#file_thumb").val(res.data.file_thumb); //点击后的大图
                        layer.msg('上传成功',{icon: 1});
                    }else{
                        layer.msg(res.msg);
                    }
                }
                ,error: function(e){
                    console.log(e)
                    //layer.msg('上传失败');

                }
            });
            //监听提交
            form.on('submit(submit)', function (data) {
                if(data.field.pic_url==''){
                    layer.alert('请上传品牌logo',{icon:2});
                    return false;
                }
            });
        });
    </script>
</block>
